<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryRef" :model="queryParams" :inline="true">
      <el-form-item label="消费类型" prop="consumeType" @change="handleQuery">
        <el-select v-model="queryParams.consumeType" clearable>
          <el-option label="场地" value="1" />
          <el-option label="商品" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="消费项目" prop="projectId">
        <el-select v-model="queryParams.projectId" @change="getSites">
          <el-option v-for="p in projectList" :key="p.id" :label="p.projectName" :value="p.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="场地" prop="siteId">
        <el-select v-model="queryParams.siteId" clearable placeholder="请选择场地" @change="handleQuery">
          <el-option v-for="item in siteList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="消费时间" prop="timeRange">
        <el-date-picker
          v-model="orderTimeArr"
          type="daterange" value-format="YYYY-MM-DD"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>  
    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="20">-->
      <!--        <el-button type="warning" plain>导出</el-button>-->
      <!--      </el-col>-->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
    </el-row>
	   
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="tableData">
      <el-table-column type="index" label="序号" width="80" align="center" />
      <el-table-column label="会员卡号" prop="memberCardCode" min-width="100" />
      <el-table-column label="手机号" prop="memberTelno" min-width="100" />
      <el-table-column label="消费项目" prop="projectName" min-width="200" />
      <el-table-column label="消费类型" prop="type" min-width="100" />
      <el-table-column label="场地/商品" prop="siteName" min-width="200" />
      <el-table-column label="场地时间" prop="orderInfo" min-width="200">
        <template #default="scope">
          {{ scope.row.orderInfo.replace(/,/,'-') }}
        </template>
      </el-table-column>
      <el-table-column label="消费时间" prop="orderTime" min-width="200" />
      <el-table-column label="消费金额" prop="orderValue" min-width="100" />
      <el-table-column label="退款金额" prop="refundValue" min-width="100" />
      <el-table-column label="余额" prop="afterValueFinal" min-width="100" />
      <!-- <el-table-column label="消费后余额" prop="afterValue" min-width="200" /> -->
    </el-table>
    <pagination
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="ven_member_recharge">
const { proxy } = getCurrentInstance()	
import { listConsume } from '../../../../api/ven/member'
import { getSiteList, projectConfigList } from '../../../../api/ven'
const loading = ref(false)
const total = ref('')
const showSearch = ref(true)
const tableData = ref([])
const data = reactive({
  projectList: [],
  siteList: [],
  orderTimeArr: [],
  queryParams: {
    pageNum: 1,
    pageSize: 10
  }
})
const { queryParams, projectList, siteList, orderTimeArr } = toRefs(data)
// 获取列表
function getList() {
  loading.value = true
  if (orderTimeArr.value) {
    queryParams.value.timeRange = orderTimeArr.value.toString()
  }
  
  listConsume(queryParams.value).then(res => {
    loading.value = false
    tableData.value = res.rows
    total.value = res.total
  })
}
// 获取项目列表
function getProjectList() {
  projectConfigList().then(res => {
    projectList.value = res.rows
  })
}
function getSites() {
  queryParams.value.siteId = ''
  siteList.value = []
  getSiteList({
    projectId: queryParams.value.projectId
  }).then(res => {
    siteList.value = res.rows
  })

  // handleQuery()
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm('queryRef')
  orderTimeArr.value = []
  siteList.value = []
  handleQuery()
}
getProjectList()
getList()
</script>

<style scoped>

</style>
